package com.bigShen.pattern.prototype.shallowClone;

import com.bigShen.pattern.prototype.JinGuBang;

/**
 * Created by lei.shen on 2018/9/23.
 */
public class MainTest {

    public static void main(String[] args) {

        ShllowQiTianDaSheng qiTianDaSheng = new ShllowQiTianDaSheng();
        JinGuBang jinGuBang = new JinGuBang();
        jinGuBang.setWeight(10);
        jinGuBang.setHeight(200);

        qiTianDaSheng.setJinGuBang(jinGuBang);
        qiTianDaSheng.setName("齐天大圣");
        qiTianDaSheng.setType("六耳猕猴");

        System.out.println(qiTianDaSheng);

        try {
            // 浅克隆
            ShllowQiTianDaSheng clone = (ShllowQiTianDaSheng) qiTianDaSheng.clone();
            System.out.println(clone.getName());
            System.out.println(clone);

            System.out.println(qiTianDaSheng == clone);

            System.out.println("克隆后内存地址是否一样: " + (qiTianDaSheng.getJinGuBang() == clone.getJinGuBang()));

            System.out.println(String.format("原体的大小 金箍棒height: %s , weight : %s",
                    qiTianDaSheng.getJinGuBang().getHeight(), qiTianDaSheng.getJinGuBang().getWeight() ));
            //修改克隆体的大小
            clone.getJinGuBang().big();
            System.out.println(String.format("修改克隆体后,原体的大小 金箍棒height: %s , weight : %s",
                    qiTianDaSheng.getJinGuBang().getHeight(), qiTianDaSheng.getJinGuBang().getWeight() ));

        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }


    }

}
